package com.binance.binancedemo.recycler;

import android.view.View;
import android.view.ViewGroup;

/**
 */
public class RecyclerBuilder {

    public static <T> BaseRecyclerCell<T, BaseRecyclerViewHolder> create(final IRecyclerCell<T> cell) {

        return new BaseRecyclerCell<T, BaseRecyclerViewHolder>(cell.getData()) {

            @Override
            public void reloadResource() {
                cell.reloadResource();
            }

            @Override
            public void releaseResource() {
                cell.releaseResource();
            }

            @Override
            public BaseRecyclerViewHolder createViewHolder(ViewGroup parent) {
                View view= cell.getView(parent);
                if(view!=null) {
                    return new BaseRecyclerViewHolder(view);
                } else {
                    return createHolderByLayout(cell.getLayoutId(), parent);
                }
            }

            @Override
            protected void onBindViewHolder(BaseRecyclerViewHolder viewHolder) {
                cell.onBindViewHolder(viewHolder);
            }

            @Override
            public int getType() {
                return cell.getType();
            }
        };
    }

}
